﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hrm.Core;
using AutoMapper.QueryableExtensions;

namespace Hrm.Services
{
    public class PermissionService :BaseService<Permission>, IPermissionService
    {
        private readonly IPermissionPermissionDbRepository _permissionRepository;

        public PermissionService(IPermissionPermissionDbRepository permissionRepository)
            : base(permissionRepository)
        {
            _permissionRepository = permissionRepository;
        }


        public PageResponse<PermissionDto> GetPageList(PageRequest<PermissionDto> request)
        {
            var query = this.GetAllAbledAndOrderByCreatetime();
            if(!string.IsNullOrEmpty(request.filter.Code))
            {
                query = query.Where(p => p.Code == request.filter.Code);
            }
            if (!string.IsNullOrEmpty(request.filter.Name))
            {
                query = query.Where(p => p.Name == request.filter.Name);
            }
            var data = query.Project().To<PermissionDto>();
            return new PageResponse<PermissionDto>(data, request.draw, request.start, request.length);
        }
    }
}
